package com.yyds.controller;

import com.yyds.common.MyJSON;
import com.yyds.common.R;
import com.yyds.service.PersonStaffService;
import com.yyds.vo.EchartBarVo;
import com.yyds.vo.PersonStaffVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 花君瑜
 * @date 2022/10/14 08:30:40
 * @desc 行政人员信息管理模块
 **/
@RestController
@RequestMapping("/admin/person/staff")
public class PersonStaffController {
    @Autowired
    private PersonStaffService personStaffService;

    //查询全部行政人员信息
    @RequestMapping("/queryAllStaff")
    public MyJSON<PersonStaffVo> queryAllPersonStaffController(@RequestParam Map<String, Object> params) {
        // 注意 这里使用 map来接受参数  前端传的不定参数 都可以封装到 map 中
        System.out.println("public MyJSON<PersonStaff> queryAllPersonStaffController(@RequestParam Map<String, Object> params) ="+params);
        return personStaffService.queryAllPersonStaffService(params);
    }

    //根据id删除行政人员信息
    @PostMapping("/deleteStaff")
    public R deletePersonStaffController(Integer staff_id) {
        System.out.println("public R deletePersonStaffController(Integer staff_id) = "+staff_id);
        int result = personStaffService.deletePersonStaffService(staff_id);
        return result > 0 ? R.ok() : R.error();
    }

    //删除部分行政人员信息
    @RequestMapping("/deleteAllStaff")
    public R deleteAllPersonStaffController(String str) {
        System.out.println("public R deleteAllPersonStaffController(String str)" + str);
        Integer i = personStaffService.deleteAllPersonStaffService(str);
        return i > 0 ? R.ok() : R.error();
    }

    //添加行政人员
    @RequestMapping("/addStaff")
    public R addPersonStaffController(PersonStaffVo personStaffVo){
        int result = personStaffService.addPersonStaffService(personStaffVo);
        return result > 0 ? R.ok() : R.error();
    }

    //修改行政人员
    @RequestMapping("/updateStaff")
    public R updatePersonStaffController(PersonStaffVo personStaffVo,Integer staff_id){
        System.out.println("public R updatePersonStaffController(PersonStaffVo personStaffVo) = "+personStaffVo);
        System.out.println(staff_id);
        int result = personStaffService.updatePersonStaffService(personStaffVo,staff_id);
        return result > 0 ? R.ok() : R.error();
    }

    //查询所有地区名称
    @RequestMapping("/queryRegionName")
    public R queryAllRegionNameController() {
        List<String> list = personStaffService.queryAllRegionNameService();
        return R.ok().data("regionName", list);
    }

    //生成地区柱状图
    @RequestMapping("/queryPersonStaffEchartBar")
    public R queryPersonStaffController(){
        //将从数据库读取的 地区名称 数量 放到集合中发送到前端
        List<EchartBarVo> list = personStaffService.queryPersonStaffService();
        return R.ok().data("regionBar",list);
    }
}
